package com.yh.spring.struts.interceptor;

import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;


public class SessionInterceptor extends MethodFilterInterceptor{
	private static Logger log = LogManager.getLogger(SessionInterceptor.class);
	private static final long serialVersionUID = 1L;

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		// TODO Auto-generated method stub
		log.info("拦截器开始。。。。。。。。。。。。。");
		/*System.out.println("拦截器开始。。。。。。。。。。。。。");*/
		//getInvocationContext()从上下文中获得session的信息
		Map<String,Object> session =invocation.getInvocationContext().getSession();
		if(session.get("data")==null){
			log.info("拦截到未登录----请重新登录-----");
			/*System.out.println("拦截到未登录----请重新登录-----");*/
			return "error";
		}
		String  result = invocation.invoke();
		//log.info("拦截器结束。。。。。。。。。。。。。");
		System.out.println("拦截器结束。。。。。。。。。。。。。");
		return result;
	}

}
